<include file="public@header"/>
</head>
<body>
    <div class="layui-fluid">
        <form action="{:url('AdminNotice/editPost')}" method="post" class="layui-form js-ajax-form">
            <div class="layui-card">
                <div class="layui-card-header">编辑公告动态</div>
                <div class="layui-card-body">
                    
                    <!-- 文章标题 -->
                                <div class="layui-form-item">
                                    <label class="layui-form-label">公告动态标题</label>
                                    <div class="layui-input-block">
                                        <input class="layui-input form-replace" type="text" value="{$result['title']}" name="post[title]" data-field="title"
                                                placeholder="{:lang('PLEASE_ENTER')}公告动态标题"/>
                                    </div>
                                </div>

                                <!-- 文章分类 -->
                                <div class="layui-form-item">
                                    <label class="layui-form-label">公告动态分类</label>
                                    <div class="layui-input-block">

                                        <!-- 单选分类 -->
                                        <select class="layui-input" name="post[sort_id]">
                                            <option value=''>{:lang('SELECT_PLEASE')}</option>
                                            <foreach name="sort" item="v" key='k'>
                                                <option value="{$k}" <if condition="$k eq $result['sort_id']">selected</if>>{$v}</option>
                                            </foreach>
                                        </select>
                                    </div>
                                </div>

                                <!-- 发布者 -->
                                <div class="layui-form-item">
                                    <label class="layui-form-label">发布者</label>
                                    <div class="layui-input-block">
                                        <input class="layui-input form-replace" type="text" name="post[user_id]"  value="{$result['user_id']}" 
                                                placeholder="{:lang('PLEASE_ENTER')}发布者"/>
                                    </div>
                                </div>

                                <!-- 文章简介 -->
                                <div class="layui-form-item">
                                    <label class="layui-form-label">公告动态简介</label>
                                    <div class="layui-input-block">
                                        <textarea class="layui-textarea" id="input-remark" name="post[intro]"">{$result['intro']}</textarea>
                                    </div>
                                </div>

                                <!-- 发布时间 -->
                                <div class="layui-form-item">
                                    <label class="layui-form-label">{:lang('PUBLISHED_TIME')}</label>
                                
                                    <div class="layui-input-block">
                                        <input class="layui-input js-layui-datetime" type="text" name="post[time]"
                                               value="{:date('Y-m-d H:i:s',$result['time'])}" id="published_time" readonly>
                                    </div>
                                </div>

                                
                                <!-- 详细内容 -->
                                <div class="layui-form-item">
                                    <label class="layui-form-label">文章内容</label>
                                    <div class="layui-input-block">
                                        <script class="form-replace" type="text/plain" id="detail_content" name="post[content]">{:htmlspecialchars_decode($result['content'])}</script>
                                    </div>
                                </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <input type="hidden" name="post[id]" value="{$result['id']}">
                            <if condition="cmf_auth_check(cmf_get_current_admin_id(), 'portal/AdminQuest/editPost')">
                                <button type="submit" class="layui-btn layui-btn-normal js-ajax-submit">{:lang('SAVE')}</button>
                            </if>
                            <a class="layui-btn layui-btn-primary" href="{:url('AdminNotice/index')}">{:lang('BACK')}</a>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>

<include file="public@footer"/>
<include file="admin@theme/scripts"/>
<script type="text/javascript">
    //编辑器路径定义
    var editorURL = GV.WEB_ROOT;
</script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.all.js"></script>
<script type="text/javascript">
    $(function () {
        if( $('#detail_content').length ){
            // $('.content-preview').show();
            UE.getEditor('detail_content');
        }
        if( $('#post_excerpt').length ){
            UE.getEditor('post_excerpt');
        }
        //移除缩略图
        $('.btn-cancel-thumbnail').click(function () {
            $('#thumbnail-preview').attr('src', '__TMPL__/public/assets/images/default-thumbnail.png');
            $('#thumbnail').val('');
        });

    });

    // 选择分类
    function doSelectCategory() {
        var selectedCategoriesId = $('#js-categories-id-input').val();
        openIframeLayer("{:url('AdminCategory/select')}?operate=add&ids=" + selectedCategoriesId, '请选择分类', {
            area: ['700px', '400px'],
            btn: ['确定', '取消'],
            yes: function (index, layero) {
                //do something

                var iframeWin          = window[layero.find('iframe')[0]['name']];
                var selectedCategories = iframeWin.confirm();
                if (selectedCategories.selectedCategoriesId.length == 0) {
                    layer.msg('请选择分类');
                    return;
                }
                $('#js-categories-id-input').val(selectedCategories.selectedCategoriesId.join(','));
                $('#js-categories-name-input').val(selectedCategories.selectedCategoriesName.join(' '));
                //console.log(layer.getFrameIndex(index));
                layer.close(index); //如果设定了yes回调，需进行手工关闭
            }
        });
    }
</script>
